package com.HQCourse.vod.vod.controller;


import com.HQCourse.result.Result;
import com.HQCourse.vod.vod.service.CourseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.HQCourse.model.vod.Course;
import com.example.HQCourse.vo.vod.CourseFormVo;
import com.example.HQCourse.vo.vod.CoursePublishVo;
import com.example.HQCourse.vo.vod.CourseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author zww
 * @since 2023-06-25
 */
@Api("课程接口")
@RestController
@RequestMapping("admin/vod/course")
//@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;
    @ApiOperation("分页查询")
    @GetMapping("{page}/{limit}")
    public Result courseList(@ApiParam(name = "page", value = "当前页码", required = true)
                                 @PathVariable Long page,
                             @ApiParam(name = "limit", value = "每页记录数", required = true)
                                 @PathVariable Long limit,
                             @ApiParam(name = "courseVo", value = "查询对象", required = false)
                                 CourseQueryVo courseQueryVo){
        Page<Course> coursePage=new Page<>(page,limit);
        Map<String,Object> map=courseService.findPage(coursePage,courseQueryVo);

        return Result.ok(map);
    }
    @ApiOperation("添加课程")
    @PostMapping("save")
    public Result save(@RequestBody CourseFormVo courseFormVo){
         Long id= courseService.saveCourseifo(courseFormVo);
        return Result.ok(id);
    }
    @ApiOperation("获取课程基本信息")
    @GetMapping("getId/{id}")
    public Result getId(@PathVariable Long id){
        CourseFormVo courseFormVo=courseService.getCourseInfoById(id);
        return Result.ok(courseFormVo);
    }
    @ApiOperation("更新课程基本信息")
    @PostMapping("update")
    public Result update(@RequestBody CourseFormVo courseFormVo){
        courseService.updateCourseId(courseFormVo);
        return Result.ok(courseFormVo.getId());
    }
    @ApiOperation("id查询发布课程信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result getCoursePublishVo(@PathVariable Long id){
        CoursePublishVo coursePublishVo=courseService.getCoursePublishVo(id);
    return Result.ok(coursePublishVo);
    }
    @ApiOperation("课程发布")
    @PostMapping("publishCourse/{id}")
    public Result publishVoForm(@PathVariable Long id){
        boolean flag=courseService.publichVoform(id);
        return Result.ok(flag);
    }
    @ApiOperation(value = "删除课程")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        courseService.removeCourseById(id);
        return Result.ok(null);
    }
    @GetMapping("findAll")
    public Result findAll() {
        List<Course> list = courseService.findlist();
        return Result.ok(list);
    }

}

